package com.java.system.controller;

import com.java.system.entity.Result;
import com.java.system.entity.Role;
import com.java.system.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  角色控制器
 * </p>
 *
 * @author xiaoman
 * @since 2023-07-21
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    IRoleService roleService;

    @GetMapping("/list")
    public Result getAllRole(){
        List<Role> roleList = roleService.select();
        Result result=Result.success();
        result.put("data",roleList);
        return result;
    }

    @PostMapping("/add")
    public Result insertRole(@RequestBody Role role){
        roleService.insertRole(role);
        return Result.success("增加角色成功");
    }
    @GetMapping("/{id}")
    public Result getRoleById(@PathVariable("id") Integer id){
        Role role = roleService.selectRoleById(id);
        Result result=Result.success();
        result.put("data",role);
        return  result;
    }
    @PutMapping()
    public Result updateRole(@RequestBody Role role){
        roleService.updateRole(role);
        return Result.success("修改角色成功");
    }

    @DeleteMapping("/{id}")
    public Result deleteRole(@PathVariable("id")Integer id){
        roleService.deleteRole(id);
        return Result.success("删除角色成功");
    }

}
